import random as rd
import json


with open('shu_du.json', 'r') as f:
	Sudoku = json.load(f)

tq = 0

sudoku = Sudoku[:]
while True:
	for i1 in range(len(sudoku)):
		for i2 in range(len(sudoku[i1])):
			for i3 in range(len(sudoku[i2])):
				if rd.randint(1, 100) <= 10:
					sudoku[i1][i2][i3] = None
	a = 0
	for i1 in range(len(sudoku)):
		for i2 in range(len(sudoku[i1])):
			for i3 in range(len(sudoku[i2])):
				if i3 == None:
					a += 1
	if a != 0:
		break
	else:
		continue

# 遍历整个数独
for i1 in range(len(sudoku)):
		for i2 in range(len(sudoku[i1])):
			for i3 in range(len(i1[i2])):
				tq += 1
				print(tq)
				# 如果空缺
				if i3 == None:
					# 遍历所有数字
					for i in range(1, 10):
						OK = True
						'''横向检测'''
						# 遍历二级循环，如[[...], [...], [...]]
						for j2 in range(len(sudoku[i1])):
							if OK == False:
								break
								# 遍历三级循环，如[..., ..., ...]
							for j3 in range(len(sudoku[j2])):
								if j3 == i:
									OK = False
									break
						if OK == False:
							break
						'''纵向检测'''
						# 遍历一级循环，如[[[...] * 3] * 3]
						for j1 in range(len(sudoku)):
							if OK == False:
								break
							# 进入二、三级列表
							if j1[i2][i3] == i:
								OK = False
								break

print(sudoku)
